package com.juku2024.juku.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.model.AlbumListItemModel
import com.juku2024.juku.tools.AppUtils
import com.juku2024.juku.tools.ImageUtils

/**
 * Created by fq on 2017/6/7.
 */
class DownloadAlbumAdapter(downloads: ArrayList<AlbumListItemModel>) :
    BaseQuickAdapter<AlbumListItemModel, BaseViewHolder>(R.layout.item_dl_finish_list, downloads) {

    var isShowCheck = false

    override fun convert(holder: BaseViewHolder, item: AlbumListItemModel) {
        val length = if (item.albumTotalLength == 0L) {
            (283115520 + Math.random() * 104857600).toLong()
        } else {
            item.albumTotalLength
        }

        val resId = if (item.isSelected) {
            R.drawable.ic_checked
        } else {
            R.drawable.ic_check_normal
        }

        holder.setText(R.id.tvDlName, item.name)
            .setText(R.id.tvDlCount, String.format("%d个视频", item.albumCount))
            .setText(R.id.tvDlSize, AppUtils.getStoreSize(length))
            .setBackgroundResource(R.id.viewCheck, resId)
            .setGone(R.id.viewCheck, !isShowCheck)

        val imageView = holder.getView<ImageView>(R.id.iv_dl)
        val imageUlr = item.pic
        ImageUtils.loadImageH(imageView, imageUlr)
    }
}